/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package negocio;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Set;

/**
 *
 * @author jeferson
 */
public class Turma implements Serializable{

    private HashMap<Integer, Aluno> alunos = new HashMap<Integer, Aluno>();
    private int serie;
    private String nome;

    public Turma(int serie, String nome) {
        this.serie = serie;
        this.nome = nome;
    }

    public int getSerie() {
        return serie;
    }

    public void setSerie(int serie) {
        this.serie = serie;
    }

    public String getNome() {
        return ""+serie+"º "+nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public ArrayList<Aluno> getArrayAlunos() {
        Set<Integer> keys = alunos.keySet();
        ArrayList<Aluno> result = new ArrayList<Aluno>();
        for (Integer key : keys) {
            result.add(alunos.get(key));
        }
        Collections.sort(result, new Comparator() {
            public int compare(Object acc1, Object acc2) {
                return (((Aluno) acc1).getNum()-((Aluno)acc2).getNum());
            }
        });
       // System.out.println(""+result.size());
        return result;
    }
    
    public HashMap<Integer, Aluno> getAlunos() {
        return this.alunos;
    }

    public void addAluno(Aluno aluno) {
        this.alunos.put(aluno.getNum(), aluno);
    }

    public void remAluno(Aluno aluno){
        this.alunos.remove(aluno.getNum());
    }

    public Aluno getAluno(int num){
        return alunos.get(num);
    }

    @Override
    public String toString(){
        return ""+serie+"º"+" "+nome;
    }

}
